package Ali;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author zhangmin
 * @create 2022-03-25 9:50
 */
public class Ali_0325_2 {
    public static void main(String[] args) {
        Scanner cin=new Scanner(System.in);
        int t=cin.nextInt();
        for (int i = 0; i < t; i++) {
            long[] nums=new long[5];
            for (int j = 0; j < 5; j++) {
                nums[j]=cin.nextLong();
            }
            Arrays.sort(nums);
            long maxxount=Math.min(nums[0]+nums[1],nums[2]);
            System.out.println(maxxount);
        }
    }
}
